{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    }
   ],
   "source": [
    "import re\n",
    "import jieba\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import logging\n",
    "\n",
    "from numpy import array\n",
    "from keras.preprocessing.text import one_hot\n",
    "from keras.preprocessing.sequence import pad_sequences\n",
    "from keras.models import Sequential, Model\n",
    "from keras.layers.core import Activation, Dropout, Dense\n",
    "from keras.layers import Flatten, LSTM\n",
    "from keras.layers.embeddings import Embedding\n",
    "from keras.preprocessing.text import Tokenizer\n",
    "from keras.layers import Input\n",
    "from keras.layers.merge import Concatenate\n",
    "from keras.models import load_model\n",
    "from keras.utils.np_utils import to_categorical\n",
    "from keras.callbacks import BaseLogger, TensorBoard\n",
    "\n",
    "#from sklearn.model_selection import train_test_split\n",
    "#from sklearn.preprocessing import MultiLabelBinarizer\n",
    "from gensim.models import word2vec\n",
    "from gensim import models\n",
    "from langconv import *\n",
    "\n",
    "%matplotlib inline\n",
    "pd.options.display.max_columns = None\n",
    "plt.rcParams['font.sans-serif']=['SimHei']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Load datasets\n",
    "train = pd.read_csv('./data/train.csv')\n",
    "val = pd.read_csv('./data/val.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['id',\n",
       " 'content',\n",
       " 'location_traffic_convenience',\n",
       " 'location_distance_from_business_district',\n",
       " 'location_easy_to_find',\n",
       " 'service_wait_time',\n",
       " 'service_waiters_attitude',\n",
       " 'service_parking_convenience',\n",
       " 'service_serving_speed',\n",
       " 'price_level',\n",
       " 'price_cost_effective',\n",
       " 'price_discount',\n",
       " 'environment_decoration',\n",
       " 'environment_noise',\n",
       " 'environment_space',\n",
       " 'environment_cleaness',\n",
       " 'dish_portion',\n",
       " 'dish_taste',\n",
       " 'dish_look',\n",
       " 'dish_recommendation',\n",
       " 'others_overall_experience',\n",
       " 'others_willing_to_consume_again']"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train.columns.values.tolist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(120000, 22) (15000, 22)\n"
     ]
    }
   ],
   "source": [
    "print(train.shape, val.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Get labels\n",
    "train_labels = train.iloc[:,2:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "val_labels = val.iloc[:,2:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>location_traffic_convenience</th>\n",
       "      <th>location_distance_from_business_district</th>\n",
       "      <th>location_easy_to_find</th>\n",
       "      <th>service_wait_time</th>\n",
       "      <th>service_waiters_attitude</th>\n",
       "      <th>service_parking_convenience</th>\n",
       "      <th>service_serving_speed</th>\n",
       "      <th>price_level</th>\n",
       "      <th>price_cost_effective</th>\n",
       "      <th>price_discount</th>\n",
       "      <th>environment_decoration</th>\n",
       "      <th>environment_noise</th>\n",
       "      <th>environment_space</th>\n",
       "      <th>environment_cleaness</th>\n",
       "      <th>dish_portion</th>\n",
       "      <th>dish_taste</th>\n",
       "      <th>dish_look</th>\n",
       "      <th>dish_recommendation</th>\n",
       "      <th>others_overall_experience</th>\n",
       "      <th>others_willing_to_consume_again</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>-2</td>\n",
       "      <td>-2</td>\n",
       "      <td>-2</td>\n",
       "      <td>-2</td>\n",
       "      <td>1</td>\n",
       "      <td>-2</td>\n",
       "      <td>-2</td>\n",
       "      <td>-2</td>\n",
       "      <td>-2</td>\n",
       "      <td>1</td>\n",
       "      <td>-2</td>\n",
       "      <td>-2</td>\n",
       "      <td>-2</td>\n",
       "      <td>-2</td>\n",
       "      <td>-2</td>\n",
       "      <td>-2</td>\n",
       "      <td>1</td>\n",
       "      <td>-2</td>\n",
       "      <td>1</td>\n",
       "      <td>-2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   location_traffic_convenience  location_distance_from_business_district  \\\n",
       "0                            -2                                        -2   \n",
       "\n",
       "   location_easy_to_find  service_wait_time  service_waiters_attitude  \\\n",
       "0                     -2                 -2                         1   \n",
       "\n",
       "   service_parking_convenience  service_serving_speed  price_level  \\\n",
       "0                           -2                     -2           -2   \n",
       "\n",
       "   price_cost_effective  price_discount  environment_decoration  \\\n",
       "0                    -2               1                      -2   \n",
       "\n",
       "   environment_noise  environment_space  environment_cleaness  dish_portion  \\\n",
       "0                 -2                 -2                    -2            -2   \n",
       "\n",
       "   dish_taste  dish_look  dish_recommendation  others_overall_experience  \\\n",
       "0          -2          1                   -2                          1   \n",
       "\n",
       "   others_willing_to_consume_again  \n",
       "0                               -2  "
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_labels.head(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\" 吼吼 吼 ， 萌死 人 的 棒棒糖 ， 中 了 大众 点评 的 霸王餐 ， 太 可爱 了 。 一直 就 好奇 这个 棒棒糖 是 怎么 个 东西 ， 大众 点评 给 了 我 这个 土老冒 一个 见识 的 机会 。 看 介绍 棒棒糖 是 用 德国 糖 做 的 ， 不会 很甜 ， 中间 的 照片 是 糯米 的 ， 能 食用 ， 真是太 高端 大气 上档次 了 ， 还 可以 买 蝴蝶结 扎口 ， 送人 可以 买 礼盒 。 我 是 先 打 的 卖家 电话 ， 加 了 微信 ， 给 卖家 传 的 照片 。 等 了 几天 ， 卖家 就 告诉 我 可以 取货 了 ， 去 大官 屯 那取 的 。 虽然 连 卖家 的 面 都 没 见到 ， 但是 还是 谢谢 卖家 送 我 这么 可爱 的 东西 ， 太 喜欢 了 ， 这 哪 舍得吃 啊 。 \"'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train['content'][0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "X_train = train['content'].tolist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "X_val = val['content'].tolist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [],
   "source": [
    "#y_train = to_categorical(train_labels + 2, num_classes=4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [],
   "source": [
    "#y_val = to_categorical(val_labels + 2, num_classes=4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Get all categories\n",
    "labels_length = len(val_labels.columns.values.tolist())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "metadata": {},
   "outputs": [],
   "source": [
    "#y = [to_categorical(val_labels.iloc[:,i] + 2, num_classes=4) for i in range(labels_length)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "y_train = [to_categorical(train_labels.iloc[:,i] + 2, num_classes=4) for i in range(labels_length)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "y_val = [to_categorical(val_labels.iloc[:,i] + 2, num_classes=4) for i in range(labels_length)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Tokenize\n",
    "max_features = 20000\n",
    "maxlen = 512\n",
    "\n",
    "tokenizer = Tokenizer(max_features)\n",
    "tokenizer.fit_on_texts(X_train)\n",
    "X_train = tokenizer.texts_to_sequences(X_train)\n",
    "X_val = tokenizer.texts_to_sequences(X_val)\n",
    "X_train = pad_sequences(X_train, padding='post', maxlen=maxlen)\n",
    "X_val = pad_sequences(X_val, padding='post', maxlen=maxlen)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((120000, 512), (15000, 512))"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X_train.shape, X_val.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Load pre_trained model\n",
    "w2v_model = word2vec.Word2Vec.load(\"train.model\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(300,)"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w2v_model.wv['测试'].shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Thanks to the author\n",
    "#https://eliyar.biz/using-pre-trained-gensim-word2vector-in-a-keras-model-and-visualizing/\n",
    "num_words = 50000\n",
    "embedding_dim = 300\n",
    "\n",
    "vocab_list = [(k, w2v_model.wv[k]) for k, v in w2v_model.wv.vocab.items()]\n",
    "\n",
    "#embeddings_matrix = np.zeros((len(w2v_model.wv.vocab.items()) + 1, w2v_model.vector_size))\n",
    "embeddings_matrix = np.zeros((num_words, embedding_dim))\n",
    "for i in range(num_words):\n",
    "    embeddings_matrix[i] = vocab_list[i][1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Log\n",
    "logdir = \"./logs/\"\n",
    "tensorBoard = TensorBoard(\n",
    "    log_dir=logdir,\n",
    "    histogram_freq=1,\n",
    "    embeddings_data=X_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Create model\n",
    "EMBEDDING_DIM = 300\n",
    "\n",
    "input_layer = Input(shape=(maxlen,))\n",
    "embedding_layer = Embedding(len(embeddings_matrix),\n",
    "                            EMBEDDING_DIM,\n",
    "                            weights=[embeddings_matrix],\n",
    "                            trainable=False)(input_layer)\n",
    "lstm_layer = LSTM(128, dropout=0.2, recurrent_dropout=0.2)(embedding_layer)\n",
    "d1 = Dense(64, activation='relu')(lstm_layer)\n",
    "layers = []\n",
    "for i in range(labels_length):\n",
    "    d2 = Dense(4, activation='sigmoid')(d1)\n",
    "    layers.append(d2)\n",
    "\n",
    "model = Model(inputs=input_layer, outputs=layers)\n",
    "model.compile(loss='categorical_crossentropy', optimizer='Adamax', metrics=['accuracy'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Model: \"model_1\"\n",
      "__________________________________________________________________________________________________\n",
      "Layer (type)                    Output Shape         Param #     Connected to                     \n",
      "==================================================================================================\n",
      "input_1 (InputLayer)            (None, 512)          0                                            \n",
      "__________________________________________________________________________________________________\n",
      "embedding_2 (Embedding)         (None, 512, 300)     15000000    input_1[0][0]                    \n",
      "__________________________________________________________________________________________________\n",
      "lstm_2 (LSTM)                   (None, 128)          219648      embedding_2[0][0]                \n",
      "__________________________________________________________________________________________________\n",
      "dense_3 (Dense)                 (None, 64)           8256        lstm_2[0][0]                     \n",
      "__________________________________________________________________________________________________\n",
      "dense_4 (Dense)                 (None, 4)            260         dense_3[0][0]                    \n",
      "__________________________________________________________________________________________________\n",
      "dense_5 (Dense)                 (None, 4)            260         dense_3[0][0]                    \n",
      "__________________________________________________________________________________________________\n",
      "dense_6 (Dense)                 (None, 4)            260         dense_3[0][0]                    \n",
      "__________________________________________________________________________________________________\n",
      "dense_7 (Dense)                 (None, 4)            260         dense_3[0][0]                    \n",
      "__________________________________________________________________________________________________\n",
      "dense_8 (Dense)                 (None, 4)            260         dense_3[0][0]                    \n",
      "__________________________________________________________________________________________________\n",
      "dense_9 (Dense)                 (None, 4)            260         dense_3[0][0]                    \n",
      "__________________________________________________________________________________________________\n",
      "dense_10 (Dense)                (None, 4)            260         dense_3[0][0]                    \n",
      "__________________________________________________________________________________________________\n",
      "dense_11 (Dense)                (None, 4)            260         dense_3[0][0]                    \n",
      "__________________________________________________________________________________________________\n",
      "dense_12 (Dense)                (None, 4)            260         dense_3[0][0]                    \n",
      "__________________________________________________________________________________________________\n",
      "dense_13 (Dense)                (None, 4)            260         dense_3[0][0]                    \n",
      "__________________________________________________________________________________________________\n",
      "dense_14 (Dense)                (None, 4)            260         dense_3[0][0]                    \n",
      "__________________________________________________________________________________________________\n",
      "dense_15 (Dense)                (None, 4)            260         dense_3[0][0]                    \n",
      "__________________________________________________________________________________________________\n",
      "dense_16 (Dense)                (None, 4)            260         dense_3[0][0]                    \n",
      "__________________________________________________________________________________________________\n",
      "dense_17 (Dense)                (None, 4)            260         dense_3[0][0]                    \n",
      "__________________________________________________________________________________________________\n",
      "dense_18 (Dense)                (None, 4)            260         dense_3[0][0]                    \n",
      "__________________________________________________________________________________________________\n",
      "dense_19 (Dense)                (None, 4)            260         dense_3[0][0]                    \n",
      "__________________________________________________________________________________________________\n",
      "dense_20 (Dense)                (None, 4)            260         dense_3[0][0]                    \n",
      "__________________________________________________________________________________________________\n",
      "dense_21 (Dense)                (None, 4)            260         dense_3[0][0]                    \n",
      "__________________________________________________________________________________________________\n",
      "dense_22 (Dense)                (None, 4)            260         dense_3[0][0]                    \n",
      "__________________________________________________________________________________________________\n",
      "dense_23 (Dense)                (None, 4)            260         dense_3[0][0]                    \n",
      "==================================================================================================\n",
      "Total params: 15,233,104\n",
      "Trainable params: 233,104\n",
      "Non-trainable params: 15,000,000\n",
      "__________________________________________________________________________________________________\n",
      "None\n"
     ]
    }
   ],
   "source": [
    "print(model.summary())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Train on 120000 samples, validate on 15000 samples\n",
      "Epoch 1/5\n",
      "120000/120000 [==============================] - 637s 5ms/step - loss: 14.9398 - dense_4_loss: 0.5969 - dense_5_loss: 0.5440 - dense_6_loss: 0.6879 - dense_7_loss: 0.4840 - dense_8_loss: 1.0236 - dense_9_loss: 0.2934 - dense_10_loss: 0.5682 - dense_11_loss: 1.2052 - dense_12_loss: 0.6894 - dense_13_loss: 0.9673 - dense_14_loss: 0.8269 - dense_15_loss: 0.6769 - dense_16_loss: 0.8866 - dense_17_loss: 0.7729 - dense_18_loss: 1.0938 - dense_19_loss: 0.8533 - dense_20_loss: 0.7631 - dense_21_loss: 0.5891 - dense_22_loss: 0.6662 - dense_23_loss: 0.7510 - dense_4_accuracy: 0.7762 - dense_5_accuracy: 0.7976 - dense_6_accuracy: 0.7677 - dense_7_accuracy: 0.8833 - dense_8_accuracy: 0.5437 - dense_9_accuracy: 0.9360 - dense_10_accuracy: 0.8448 - dense_11_accuracy: 0.5026 - dense_12_accuracy: 0.7639 - dense_13_accuracy: 0.6126 - dense_14_accuracy: 0.6729 - dense_15_accuracy: 0.7486 - dense_16_accuracy: 0.6746 - dense_17_accuracy: 0.6980 - dense_18_accuracy: 0.5429 - dense_19_accuracy: 0.6244 - dense_20_accuracy: 0.7250 - dense_21_accuracy: 0.8068 - dense_22_accuracy: 0.7348 - dense_23_accuracy: 0.6529 - val_loss: 14.2370 - val_dense_4_loss: 0.5725 - val_dense_5_loss: 0.5342 - val_dense_6_loss: 0.6698 - val_dense_7_loss: 0.4841 - val_dense_8_loss: 0.9575 - val_dense_9_loss: 0.2886 - val_dense_10_loss: 0.5673 - val_dense_11_loss: 1.2018 - val_dense_12_loss: 0.6774 - val_dense_13_loss: 0.9561 - val_dense_14_loss: 0.7022 - val_dense_15_loss: 0.5967 - val_dense_16_loss: 0.8095 - val_dense_17_loss: 0.6868 - val_dense_18_loss: 1.0894 - val_dense_19_loss: 0.8275 - val_dense_20_loss: 0.7634 - val_dense_21_loss: 0.5840 - val_dense_22_loss: 0.6108 - val_dense_23_loss: 0.6689 - val_dense_4_accuracy: 0.7838 - val_dense_5_accuracy: 0.8021 - val_dense_6_accuracy: 0.7677 - val_dense_7_accuracy: 0.8825 - val_dense_8_accuracy: 0.5985 - val_dense_9_accuracy: 0.9364 - val_dense_10_accuracy: 0.8451 - val_dense_11_accuracy: 0.4999 - val_dense_12_accuracy: 0.7619 - val_dense_13_accuracy: 0.6174 - val_dense_14_accuracy: 0.7393 - val_dense_15_accuracy: 0.7876 - val_dense_16_accuracy: 0.7124 - val_dense_17_accuracy: 0.7339 - val_dense_18_accuracy: 0.5425 - val_dense_19_accuracy: 0.6380 - val_dense_20_accuracy: 0.7193 - val_dense_21_accuracy: 0.8058 - val_dense_22_accuracy: 0.7539 - val_dense_23_accuracy: 0.7187\n",
      "Epoch 2/5\n",
      "120000/120000 [==============================] - 601s 5ms/step - loss: 14.0163 - dense_4_loss: 0.5774 - dense_5_loss: 0.5355 - dense_6_loss: 0.6489 - dense_7_loss: 0.4823 - dense_8_loss: 0.8184 - dense_9_loss: 0.2885 - dense_10_loss: 0.5626 - dense_11_loss: 1.1919 - dense_12_loss: 0.6275 - dense_13_loss: 0.9600 - dense_14_loss: 0.7185 - dense_15_loss: 0.5931 - dense_16_loss: 0.8170 - dense_17_loss: 0.6867 - dense_18_loss: 1.0888 - dense_19_loss: 0.8318 - dense_20_loss: 0.7590 - dense_21_loss: 0.5903 - dense_22_loss: 0.6313 - dense_23_loss: 0.6068 - dense_4_accuracy: 0.7762 - dense_5_accuracy: 0.7976 - dense_6_accuracy: 0.7743 - dense_7_accuracy: 0.8833 - dense_8_accuracy: 0.6856 - dense_9_accuracy: 0.9360 - dense_10_accuracy: 0.8448 - dense_11_accuracy: 0.5025 - dense_12_accuracy: 0.7805 - dense_13_accuracy: 0.6128 - dense_14_accuracy: 0.7316 - dense_15_accuracy: 0.7922 - dense_16_accuracy: 0.7078 - dense_17_accuracy: 0.7320 - dense_18_accuracy: 0.5434 - dense_19_accuracy: 0.6355 - dense_20_accuracy: 0.7253 - dense_21_accuracy: 0.8071 - dense_22_accuracy: 0.7492 - dense_23_accuracy: 0.7641 - val_loss: 13.3693 - val_dense_4_loss: 0.5447 - val_dense_5_loss: 0.5186 - val_dense_6_loss: 0.5850 - val_dense_7_loss: 0.4838 - val_dense_8_loss: 0.6667 - val_dense_9_loss: 0.2840 - val_dense_10_loss: 0.5598 - val_dense_11_loss: 1.1725 - val_dense_12_loss: 0.5232 - val_dense_13_loss: 0.9473 - val_dense_14_loss: 0.6918 - val_dense_15_loss: 0.5799 - val_dense_16_loss: 0.7805 - val_dense_17_loss: 0.6599 - val_dense_18_loss: 1.0856 - val_dense_19_loss: 0.8187 - val_dense_20_loss: 0.7633 - val_dense_21_loss: 0.5879 - val_dense_22_loss: 0.5909 - val_dense_23_loss: 0.5352 - val_dense_4_accuracy: 0.7838 - val_dense_5_accuracy: 0.8021 - val_dense_6_accuracy: 0.7972 - val_dense_7_accuracy: 0.8825 - val_dense_8_accuracy: 0.7591 - val_dense_9_accuracy: 0.9364 - val_dense_10_accuracy: 0.8451 - val_dense_11_accuracy: 0.5021 - val_dense_12_accuracy: 0.8391 - val_dense_13_accuracy: 0.6174 - val_dense_14_accuracy: 0.7384 - val_dense_15_accuracy: 0.7965 - val_dense_16_accuracy: 0.7178 - val_dense_17_accuracy: 0.7368 - val_dense_18_accuracy: 0.5428 - val_dense_19_accuracy: 0.6390 - val_dense_20_accuracy: 0.7197 - val_dense_21_accuracy: 0.8060 - val_dense_22_accuracy: 0.7649 - val_dense_23_accuracy: 0.8053\n",
      "Epoch 3/5\n",
      "120000/120000 [==============================] - 625s 5ms/step - loss: 13.3800 - dense_4_loss: 0.5337 - dense_5_loss: 0.5207 - dense_6_loss: 0.5623 - dense_7_loss: 0.4817 - dense_8_loss: 0.6782 - dense_9_loss: 0.2820 - dense_10_loss: 0.5586 - dense_11_loss: 1.1653 - dense_12_loss: 0.5134 - dense_13_loss: 0.9422 - dense_14_loss: 0.7120 - dense_15_loss: 0.5852 - dense_16_loss: 0.8016 - dense_17_loss: 0.6733 - dense_18_loss: 1.0831 - dense_19_loss: 0.8132 - dense_20_loss: 0.7575 - dense_21_loss: 0.5852 - dense_22_loss: 0.6068 - dense_23_loss: 0.5243 - dense_4_accuracy: 0.7814 - dense_5_accuracy: 0.7971 - dense_6_accuracy: 0.8147 - dense_7_accuracy: 0.8833 - dense_8_accuracy: 0.7540 - dense_9_accuracy: 0.9360 - dense_10_accuracy: 0.8448 - dense_11_accuracy: 0.4988 - dense_12_accuracy: 0.8398 - dense_13_accuracy: 0.6143 - dense_14_accuracy: 0.7310 - dense_15_accuracy: 0.7977 - dense_16_accuracy: 0.7122 - dense_17_accuracy: 0.7379 - dense_18_accuracy: 0.5434 - dense_19_accuracy: 0.6454 - dense_20_accuracy: 0.7254 - dense_21_accuracy: 0.8071 - dense_22_accuracy: 0.7613 - dense_23_accuracy: 0.8077 - val_loss: 12.9360 - val_dense_4_loss: 0.4767 - val_dense_5_loss: 0.5030 - val_dense_6_loss: 0.5234 - val_dense_7_loss: 0.4819 - val_dense_8_loss: 0.6273 - val_dense_9_loss: 0.2762 - val_dense_10_loss: 0.5553 - val_dense_11_loss: 1.1530 - val_dense_12_loss: 0.4907 - val_dense_13_loss: 0.9326 - val_dense_14_loss: 0.6905 - val_dense_15_loss: 0.5774 - val_dense_16_loss: 0.7720 - val_dense_17_loss: 0.6476 - val_dense_18_loss: 1.0775 - val_dense_19_loss: 0.7811 - val_dense_20_loss: 0.7561 - val_dense_21_loss: 0.5742 - val_dense_22_loss: 0.5740 - val_dense_23_loss: 0.4726 - val_dense_4_accuracy: 0.8059 - val_dense_5_accuracy: 0.8017 - val_dense_6_accuracy: 0.8177 - val_dense_7_accuracy: 0.8825 - val_dense_8_accuracy: 0.7693 - val_dense_9_accuracy: 0.9364 - val_dense_10_accuracy: 0.8451 - val_dense_11_accuracy: 0.5024 - val_dense_12_accuracy: 0.8468 - val_dense_13_accuracy: 0.6195 - val_dense_14_accuracy: 0.7420 - val_dense_15_accuracy: 0.7971 - val_dense_16_accuracy: 0.7218 - val_dense_17_accuracy: 0.7468 - val_dense_18_accuracy: 0.5435 - val_dense_19_accuracy: 0.6555 - val_dense_20_accuracy: 0.7198 - val_dense_21_accuracy: 0.8059 - val_dense_22_accuracy: 0.7715 - val_dense_23_accuracy: 0.8294\n",
      "Epoch 4/5\n",
      "120000/120000 [==============================] - 590s 5ms/step - loss: 13.0102 - dense_4_loss: 0.4788 - dense_5_loss: 0.5083 - dense_6_loss: 0.5279 - dense_7_loss: 0.4798 - dense_8_loss: 0.6535 - dense_9_loss: 0.2748 - dense_10_loss: 0.5549 - dense_11_loss: 1.1172 - dense_12_loss: 0.5201 - dense_13_loss: 0.9296 - dense_14_loss: 0.7019 - dense_15_loss: 0.5782 - dense_16_loss: 0.7952 - dense_17_loss: 0.6611 - dense_18_loss: 1.0693 - dense_19_loss: 0.7721 - dense_20_loss: 0.7515 - dense_21_loss: 0.5494 - dense_22_loss: 0.5912 - dense_23_loss: 0.4950 - dense_4_accuracy: 0.8054 - dense_5_accuracy: 0.7966 - dense_6_accuracy: 0.8226 - dense_7_accuracy: 0.8833 - dense_8_accuracy: 0.7622 - dense_9_accuracy: 0.9360 - dense_10_accuracy: 0.8448 - dense_11_accuracy: 0.5184 - dense_12_accuracy: 0.8268 - dense_13_accuracy: 0.6170 - dense_14_accuracy: 0.7332 - dense_15_accuracy: 0.7980 - dense_16_accuracy: 0.7122 - dense_17_accuracy: 0.7415 - dense_18_accuracy: 0.5451 - dense_19_accuracy: 0.6563 - dense_20_accuracy: 0.7256 - dense_21_accuracy: 0.8093 - dense_22_accuracy: 0.7678 - dense_23_accuracy: 0.8212 - val_loss: 12.5836 - val_dense_4_loss: 0.4504 - val_dense_5_loss: 0.4943 - val_dense_6_loss: 0.4947 - val_dense_7_loss: 0.4796 - val_dense_8_loss: 0.6135 - val_dense_9_loss: 0.2673 - val_dense_10_loss: 0.5516 - val_dense_11_loss: 1.0913 - val_dense_12_loss: 0.5186 - val_dense_13_loss: 0.9168 - val_dense_14_loss: 0.6746 - val_dense_15_loss: 0.5651 - val_dense_16_loss: 0.7578 - val_dense_17_loss: 0.6257 - val_dense_18_loss: 1.0619 - val_dense_19_loss: 0.7450 - val_dense_20_loss: 0.7538 - val_dense_21_loss: 0.4908 - val_dense_22_loss: 0.5656 - val_dense_23_loss: 0.4728 - val_dense_4_accuracy: 0.8087 - val_dense_5_accuracy: 0.7978 - val_dense_6_accuracy: 0.8397 - val_dense_7_accuracy: 0.8825 - val_dense_8_accuracy: 0.7773 - val_dense_9_accuracy: 0.9364 - val_dense_10_accuracy: 0.8451 - val_dense_11_accuracy: 0.5293 - val_dense_12_accuracy: 0.8221 - val_dense_13_accuracy: 0.6256 - val_dense_14_accuracy: 0.7431 - val_dense_15_accuracy: 0.8094 - val_dense_16_accuracy: 0.7319 - val_dense_17_accuracy: 0.7573 - val_dense_18_accuracy: 0.5465 - val_dense_19_accuracy: 0.6654 - val_dense_20_accuracy: 0.7205 - val_dense_21_accuracy: 0.8191 - val_dense_22_accuracy: 0.7763 - val_dense_23_accuracy: 0.8321\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 5/5\n",
      "120000/120000 [==============================] - 575s 5ms/step - loss: 12.7214 - dense_4_loss: 0.4510 - dense_5_loss: 0.5005 - dense_6_loss: 0.5095 - dense_7_loss: 0.4772 - dense_8_loss: 0.6388 - dense_9_loss: 0.2700 - dense_10_loss: 0.5509 - dense_11_loss: 1.0830 - dense_12_loss: 0.5296 - dense_13_loss: 0.9091 - dense_14_loss: 0.6872 - dense_15_loss: 0.5689 - dense_16_loss: 0.7857 - dense_17_loss: 0.6485 - dense_18_loss: 1.0574 - dense_19_loss: 0.7540 - dense_20_loss: 0.7464 - dense_21_loss: 0.4818 - dense_22_loss: 0.5848 - dense_23_loss: 0.4869 - dense_4_accuracy: 0.8151 - dense_5_accuracy: 0.7972 - dense_6_accuracy: 0.8302 - dense_7_accuracy: 0.8833 - dense_8_accuracy: 0.7655 - dense_9_accuracy: 0.9360 - dense_10_accuracy: 0.8448 - dense_11_accuracy: 0.5376 - dense_12_accuracy: 0.8144 - dense_13_accuracy: 0.6285 - dense_14_accuracy: 0.7419 - dense_15_accuracy: 0.8030 - dense_16_accuracy: 0.7159 - dense_17_accuracy: 0.7457 - dense_18_accuracy: 0.5507 - dense_19_accuracy: 0.6653 - dense_20_accuracy: 0.7261 - dense_21_accuracy: 0.8293 - dense_22_accuracy: 0.7705 - dense_23_accuracy: 0.8258 - val_loss: 12.2848 - val_dense_4_loss: 0.4176 - val_dense_5_loss: 0.4858 - val_dense_6_loss: 0.4833 - val_dense_7_loss: 0.4740 - val_dense_8_loss: 0.6016 - val_dense_9_loss: 0.2659 - val_dense_10_loss: 0.5480 - val_dense_11_loss: 1.0749 - val_dense_12_loss: 0.5144 - val_dense_13_loss: 0.8697 - val_dense_14_loss: 0.6460 - val_dense_15_loss: 0.5486 - val_dense_16_loss: 0.7424 - val_dense_17_loss: 0.6179 - val_dense_18_loss: 1.0469 - val_dense_19_loss: 0.7398 - val_dense_20_loss: 0.7472 - val_dense_21_loss: 0.4547 - val_dense_22_loss: 0.5625 - val_dense_23_loss: 0.4520 - val_dense_4_accuracy: 0.8294 - val_dense_5_accuracy: 0.8020 - val_dense_6_accuracy: 0.8453 - val_dense_7_accuracy: 0.8825 - val_dense_8_accuracy: 0.7811 - val_dense_9_accuracy: 0.9364 - val_dense_10_accuracy: 0.8451 - val_dense_11_accuracy: 0.5469 - val_dense_12_accuracy: 0.8247 - val_dense_13_accuracy: 0.6626 - val_dense_14_accuracy: 0.7633 - val_dense_15_accuracy: 0.8135 - val_dense_16_accuracy: 0.7338 - val_dense_17_accuracy: 0.7584 - val_dense_18_accuracy: 0.5581 - val_dense_19_accuracy: 0.6722 - val_dense_20_accuracy: 0.7203 - val_dense_21_accuracy: 0.8395 - val_dense_22_accuracy: 0.7817 - val_dense_23_accuracy: 0.8381\n"
     ]
    }
   ],
   "source": [
    "#Train\n",
    "history = model.fit(X_train, \n",
    "                    y_train, \n",
    "                    batch_size=128,\n",
    "                    epochs=5, \n",
    "                    validation_data=(X_val, y_val),\n",
    "                    callbacks=[tensorBoard])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Predict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 154,
   "metadata": {},
   "outputs": [],
   "source": [
    "test = pd.read_csv('./data/test.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [],
   "source": [
    "X_test = test['content'].tolist()\n",
    "X_test = tokenizer.texts_to_sequences(X_test)\n",
    "X_test = pad_sequences(X_test, padding='post', maxlen=maxlen)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_pred = model.predict(X_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(20, 15000, 4)"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.array(test_pred).shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [],
   "source": [
    "result = np.argmax(test_pred, axis=2) - 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(array([[-2, -2,  1, ..., -2, -2,  1],\n",
       "        [-2, -2, -2, ..., -2, -2, -2],\n",
       "        [-2, -2,  1, ...,  1, -2,  1],\n",
       "        ...,\n",
       "        [-2, -2, -2, ..., -2, -2, -2],\n",
       "        [ 1,  0,  0, ...,  1,  1,  1],\n",
       "        [ 1, -2, -2, ..., -2,  1,  1]], dtype=int64), (20, 15000))"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.array(result), np.array(result).shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "metadata": {},
   "outputs": [],
   "source": [
    "test.iloc[:, 2:].fillna(0, inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "metadata": {},
   "outputs": [],
   "source": [
    "test.iloc[:, 2:] = test.iloc[:, 2:].astype('int64')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 160,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(15000, 22)"
      ]
     },
     "execution_count": 160,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.DataFrame(result.T)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "      <th>9</th>\n",
       "      <th>10</th>\n",
       "      <th>11</th>\n",
       "      <th>12</th>\n",
       "      <th>13</th>\n",
       "      <th>14</th>\n",
       "      <th>15</th>\n",
       "      <th>16</th>\n",
       "      <th>17</th>\n",
       "      <th>18</th>\n",
       "      <th>19</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>-2</td>\n",
       "      <td>-2</td>\n",
       "      <td>-2</td>\n",
       "      <td>-2</td>\n",
       "      <td>1</td>\n",
       "      <td>-2</td>\n",
       "      <td>-2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>-2</td>\n",
       "      <td>1</td>\n",
       "      <td>-2</td>\n",
       "      <td>-2</td>\n",
       "      <td>-2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>-2</td>\n",
       "      <td>-2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   0   1   2   3   4   5   6   7   8   9   10  11  12  13  14  15  16  17  18  \\\n",
       "0  -2  -2  -2  -2   1  -2  -2   1   1  -2   1  -2  -2  -2   1   1  -2  -2   1   \n",
       "\n",
       "   19  \n",
       "0   1  "
      ]
     },
     "execution_count": 106,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(15000, 20)"
      ]
     },
     "execution_count": 107,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 157,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(labels_length):\n",
    "    test.iloc[:, i + 2] = df.iloc[:, i]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 159,
   "metadata": {},
   "outputs": [],
   "source": [
    "test.to_csv('./data/submission.csv', index=False, encoding='utf_8_sig')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 142,
   "metadata": {},
   "outputs": [],
   "source": [
    "model.save('my_model.h5')  # creates a HDF5 file 'my_model.h5'\n",
    "del model  # deletes the existing model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:From D:\\Anaconda\\lib\\site-packages\\tensorflow_core\\python\\ops\\resource_variable_ops.py:1630: calling BaseResourceVariable.__init__ (from tensorflow.python.ops.resource_variable_ops) with constraint is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "If using Keras pass *_constraint arguments to layers.\n",
      "WARNING:tensorflow:From D:\\Anaconda\\lib\\site-packages\\tensorflow_core\\python\\ops\\math_grad.py:1424: where (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Use tf.where in 2.0, which has the same broadcast rule as np.where\n",
      "WARNING:tensorflow:From D:\\Anaconda\\lib\\site-packages\\keras\\backend\\tensorflow_backend.py:422: The name tf.global_variables is deprecated. Please use tf.compat.v1.global_variables instead.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "#Do comment sentiment analysis\n",
    "#Load model\n",
    "model = load_model('my_model.h5')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "text = '家庭聚餐去的，水煮鱼比较香，没什么辣度，基本鱼肉都是尾巴什么的。\\\n",
    "夫妻肺片不推荐。晾杆毛肚还是挺不错的，毛肚比较嫩，蘸酱虽然还是寡淡了但调味很鲜明，十分搭百叶的味道~服务蛮不错的，环境也好。\\\n",
    "总体除了川菜之外的菜品都还比较有水准，价格偏高。\\\n",
    "川菜嘛，北师大学五食堂的川菜都秒这家八条街真的。。。\\\n",
    "看着名字对这家的川菜湘菜寄予了很高期望，结果虽说不上大大失望也是丝毫没有惊喜的，可能渝湘的同时还要顾及江南二字吧。。。'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "def cut(string):\n",
    "    line = Converter('zh-hans').convert(string)\n",
    "    string = line.replace('\\n', '')\n",
    "    w_list = jieba.cut(string)\n",
    "    return [' '.join(w for w in w_list)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Building prefix dict from the default dictionary ...\n",
      "Loading model from cache C:\\Users\\Dracu\\AppData\\Local\\Temp\\jieba.cache\n",
      "Loading model cost 0.637 seconds.\n",
      "Prefix dict has been built succesfully.\n"
     ]
    }
   ],
   "source": [
    "c_text = cut(text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "max_features = 20000\n",
    "maxlen = 512\n",
    "\n",
    "train = pd.read_csv('./data/train.csv')\n",
    "X_train = train['content'].tolist()\n",
    "tokenizer = Tokenizer(max_features)\n",
    "tokenizer.fit_on_texts(X_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "c_text = tokenizer.texts_to_sequences(c_text)\n",
    "c_text = pad_sequences(c_text, padding='post', maxlen=maxlen)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "r_text = model.predict(c_text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(20, 1, 4)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.array(r_text).shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "r_text = np.argmax(r_text, axis=2) - 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-2, -2, -2, -2,  1, -2, -2, -2, -2, -2,  1,  1,  1,  1, -2,  0,\n",
       "        -2, -2,  1, -2]], dtype=int64)"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_text.T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-2, -2, -2, -2,  1, -2, -2, -2, -2, -2,  1,  1,  1,  1, -2,  0, -2,\n",
       "       -2,  1, -2], dtype=int64)"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r_text.T[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "labels = pd.read_csv('./data/labels.csv', header=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "labels.rename(columns={0:'Category'}, inplace=True)\n",
    "labels['Values'] = r_text.T[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Category</th>\n",
       "      <th>Values</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>location_traffic_convenience</td>\n",
       "      <td>-2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>location_distance_from_business_district</td>\n",
       "      <td>-2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>location_easy_to_find</td>\n",
       "      <td>-2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>service_wait_time</td>\n",
       "      <td>-2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>service_waiters_attitude</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>service_parking_convenience</td>\n",
       "      <td>-2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>service_serving_speed</td>\n",
       "      <td>-2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>price_level</td>\n",
       "      <td>-2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>price_cost_effective</td>\n",
       "      <td>-2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>price_discount</td>\n",
       "      <td>-2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>environment_decoration</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>environment_noise</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>environment_space</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>environment_cleaness</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>dish_portion</td>\n",
       "      <td>-2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>dish_taste</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>dish_look</td>\n",
       "      <td>-2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>dish_recommendation</td>\n",
       "      <td>-2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>others_overall_experience</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>others_willing_to_consume_again</td>\n",
       "      <td>-2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                    Category  Values\n",
       "0               location_traffic_convenience      -2\n",
       "1   location_distance_from_business_district      -2\n",
       "2                      location_easy_to_find      -2\n",
       "3                          service_wait_time      -2\n",
       "4                   service_waiters_attitude       1\n",
       "5                service_parking_convenience      -2\n",
       "6                      service_serving_speed      -2\n",
       "7                                price_level      -2\n",
       "8                       price_cost_effective      -2\n",
       "9                             price_discount      -2\n",
       "10                    environment_decoration       1\n",
       "11                         environment_noise       1\n",
       "12                         environment_space       1\n",
       "13                      environment_cleaness       1\n",
       "14                              dish_portion      -2\n",
       "15                                dish_taste       0\n",
       "16                                 dish_look      -2\n",
       "17                       dish_recommendation      -2\n",
       "18                 others_overall_experience       1\n",
       "19           others_willing_to_consume_again      -2"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "labels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
